<?php

/**
 * finalClothQcTestFormItem actions.
 *
 * @package    WacStorehouse
 * @subpackage finalClothQcTestFormItem
 * @author     JianBinBi
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class finalClothQcTestFormItemActions extends WacCommonActions {
    /**
     * get searching list
     * @package
     * @author     ben
     */
    public function executeGetList(sfWebRequest $request) {

        $jqGridDataHelper = JqGridDataHelper::getInstance();

        $arrParam = array();
        if($jqGridDataHelper->loadComplexQuery($request)) {

            if($request->hasParameter(JqGridDataHelper::$KEY_SEARCH_FIELD) && $request->getParameter(JqGridDataHelper::$KEY_SEARCH_OPER)!="") {
                $arrParam['andWhere'] = array(
                        $jqGridDataHelper->getCondMapStr($request->getParameter(JqGridDataHelper::$KEY_SEARCH_OPER), "t1.".$request->getParameter(JqGridDataHelper::$KEY_SEARCH_FIELD), $request->getParameter(JqGridDataHelper::$KEY_SEARCH_STRING))
                );
            }

            if($request->hasParameter(JqGridDataHelper::$KEY_SIDX)) {
                switch($request->getParameter(JqGridDataHelper::$KEY_SIDX)) {
                    case "qc_form_code":
                        $arrParam['orderBy'] = "wp.code ".$request->getParameter(JqGridDataHelper::$KEY_SORD);
                        break;
                    case "goods_name":
                        $arrParam['orderBy'] = "wg.name ".$request->getParameter(JqGridDataHelper::$KEY_SORD);
                        break;
                    default:
                        $arrParam['orderBy'] = "t1.".$request->getParameter(JqGridDataHelper::$KEY_SIDX)." ".$request->getParameter(JqGridDataHelper::$KEY_SORD);
                        break;
                }
            }

            $resultSet = $this->mainModuleTable->getCustomList($arrParam, $request->getParameter(JqGridDataHelper::$KEY_PAGE), $request->getParameter(JqGridDataHelper::$KEY_ROWS), false);
        }
        else {
            if($request->hasParameter(JqGridDataHelper::$KEY_SEARCH_FIELD) && $request->getParameter(JqGridDataHelper::$KEY_SEARCH_FIELD)=="parent_id") {
                $arrParam['andWhere'][] = "parent_id=".$this->getRequest()->getParameter(JqGridDataHelper::$KEY_SEARCH_STRING);
            }
            $resultSet = $this->mainModuleTable->getCommonList($request->getParameter(JqGridDataHelper::$KEY_PAGE), $request->getParameter(JqGridDataHelper::$KEY_ROWS), false, $arrParam);
        }

        $filterResultSet = $this->filterList($resultSet);

        $pager = $this->mainModuleTable->getPager();
        $filterResultSet = $jqGridDataHelper->convert($filterResultSet, $pager, JsCommonData::getSuccessDatum());

        return OutputHelper::getInstance()->outputJsonOrTextFormat($filterResultSet, $this);
    }

    /*
   * override filter list
    */
    public function filterList($listObjs) {
        $filterArr = array();
        if(count($listObjs) > 0) {
            foreach($listObjs as $listObj) {
                $tmpArr = $listObj->toArray();
                $tmpArr['qc_form_code']         = $listObj->getWacParent()->getCode();
                $tmpArr['goods_name']           = $listObj->getWacGoods()->getName();
                $tmpArr['goods_number_unit_code'] = $listObj->getWacGoodsNumberUnitCode()->getName();
//                $tmpArr['weight_name']          = $listObj->getWeight().$listObj->getWacWeightUnitCode()->getName();
//                $tmpArr['roll_name']            = $listObj->getRoll().$listObj->getWacRollUnitCode()->getName();

                $filterArr[] = $tmpArr;
            }
        }

        return $filterArr;
    }
}
